Skip to content

sonic/validator: replace sonic-yang-mgmt+libyang with generated Pydan… - #2253

Merged
berendt merged 1 commit into
mainfrom
change-sonic-validate
May 4, 2026
Merged

sonic/validator: replace sonic-yang-mgmt+libyang with generated Pydan…#2253
berendt merged 1 commit into
mainfrom
change-sonic-validate

Conversation

@berendt

@berendt berendt commented May 4, 2026

Copy link
Copy Markdown
Member

…tic schemas

The previous validator imported sonic_yang (a SWIG binding to libyang1) which is not packaged for Alpine and is not available on the runtime image. Replace it with a build-time YANG→Pydantic transpiler whose committed output is the runtime schema source — runtime needs only pydantic, no native dependencies.

  • tools/sonic_yang_to_pydantic.py walks pyang's AST over files/sonic/yang_models/ and emits one Pydantic v2 model per ConfigDB table.
  • osism/tasks/conductor/sonic/_generated/_schemas.py is the committed output (205 tables); regenerated via the tool when YANG models are refreshed.
  • Validator API stays stable for callers; ValidatorUnavailable / load_yang_context are dropped along with the --yang-dir flag and SONIC_YANG_MODELS_DIR setting.
  • Tables not yet covered by upstream YANG are reported as warnings, not errors.
  • Containerfile drops libyang apk and the yang_models COPY; requirements.sonic.txt switches from the sonic-yang-mgmt VCS pin to pydantic; pyang moves out of runtime requirements (only needed when regenerating).

Cross-table leafref enforcement is intentionally out of scope here and tracked in #2252.

AI-assisted: Claude Code

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @berendt, your pull request is larger than the review limit of 150000 diff characters

@berendt
berendt force-pushed the change-sonic-validate branch from 71e5dd2 to a50fbe9 Compare May 4, 2026 20:02
…tic schemas

The previous validator imported sonic_yang (a SWIG binding to libyang1) which
is not packaged for Alpine and is not available on the runtime image. Replace
it with a build-time YANG→Pydantic transpiler whose committed output is the
runtime schema source — runtime needs only pydantic, no native dependencies.

- tools/sonic_yang_to_pydantic.py walks pyang's AST over files/sonic/yang_models/
  and emits one Pydantic v2 model per ConfigDB table.
- osism/tasks/conductor/sonic/_generated/_schemas.py is the committed output
  (205 tables); regenerated via the tool when YANG models are refreshed.
- Validator API stays stable for callers; ValidatorUnavailable / load_yang_context
  are dropped along with the --yang-dir flag and SONIC_YANG_MODELS_DIR setting.
- Tables not yet covered by upstream YANG are reported as warnings, not errors.
- Containerfile drops libyang apk and the yang_models COPY; requirements.sonic.txt
  switches from the sonic-yang-mgmt VCS pin to pydantic; pyang moves out of
  runtime requirements (only needed when regenerating).

Cross-table leafref enforcement is intentionally out of scope here and tracked
in #2252.

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
@berendt
berendt force-pushed the change-sonic-validate branch from a50fbe9 to e235a7d Compare May 4, 2026 20:04
@berendt
berendt merged commit 0b94020 into main May 4, 2026
3 checks passed
@berendt
berendt deleted the change-sonic-validate branch May 4, 2026 20:23
osfrickler pushed a commit that referenced this pull request Jun 2, 2026
The sonic-yang-mgmt git dependency was added in #2191 for the original
libyang-based SONiC config validator. #2253 replaced that validator with
offline-generated Pydantic schemas and cleaned up requirements.txt,
requirements.sonic.txt and the Containerfile, but left the dependency
behind in Pipfile/Pipfile.lock.

Nothing imports sonic_yang_mgmt anymore (the runtime validator depends only
on pydantic, and the schema generator uses pyang), so remove it from both
files and refresh the Pipfile hash.

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant